package com.asman.vr.dto

import androidx.annotation.MainThread
import com.asman.vr.network.Api
import com.asman.vr.network.RequestBody
import com.asman.vr.network.liveData
import com.asman.vr.network.liveDataNull
import retrofit2.Call
import java.util.concurrent.Executor

class ScoreRepository(private val api: Api, private val networkExecutor: Executor) {

    var tagCall: Call<BaseRes<List<ScoreTagData>>>? = null

    fun getTagCall(scoreTagSearches: List<RequestBody.QueryTags>): Call<BaseRes<List<ScoreTagData>>> {
        tagCall?.cancel()
        tagCall = api.getTagList(scoreTagSearches)
        return tagCall!!
    }

    fun getTagList(scoreTagSearches: List<RequestBody.QueryTags>) =
        liveData(getTagCall(scoreTagSearches))

    @MainThread
    fun addScore(addScore: RequestBody.AddScore) = liveDataNull(api.addScore(addScore))

}